﻿using System;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using ZechatApp.Messages;

namespace ZechatApp.ViewModels;

public partial class MainViewModel : ViewModelBase
{
    public MainViewModel()
    {
        WeakReferenceMessenger.Default.Register<BzMessage>(this, (r, m) =>
        {
            Console.WriteLine($"receive msg: {m.Value}");
            if (string.IsNullOrWhiteSpace(m.Value.Token))
            {
                CurrentPage = new LoginPageViewModel();
            }
            else
            {
                CurrentPage = new HomePageViewModel(m.Value.Username ?? "123123");
            }
        });
    }

    [ObservableProperty] private ViewModelBase _currentPage = new LoginPageViewModel();
}